package com.api.server.controller;


import com.api.server.pojo.*;
import com.api.server.service.IManagementService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shi
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/management")
public class ManagementController {

    @Autowired
    private IManagementService managementService;

    //根据管理单位id查询管理单位信息
    @ApiOperation(value = "根据管理单位id查询管理单位信息")
    @PostMapping("/message")
    public RespBean message(String managementnumber){
        Management management = managementService.message(managementnumber);
        return Result.success("获取管理单位信息成功！",management);
    }


    //增加场馆
    @ApiOperation(value = "增加管理单位")
    @PostMapping
    public Result add(@RequestBody Management management){
        if (managementService.message(management.getManagementnumber())!=null){
            return Result.fail("该管理单位编号已经被使用！");
        }
        managementService.add(management);
        return Result.success(201,"管理单位创建成功",management);
    }


    //根据id删除管理单位
    @ApiOperation(value = "删除管理单位")
    @DeleteMapping("/{id}")
    public RespBean delete(@PathVariable("id") String id){
        Management management = managementService.getById(id);
        if (management.getManagementnumber()==null){
            return Result.fail("不存在该管理单位！");
        }
        managementService.delete(id);
        return RespBean.success("删除管理单位成功！");
    }



    //根据id编辑管理单位信息
    @ApiOperation(value = "根据id编辑管理单位信息")
    @PutMapping("/updata")
    public RespBean updataById(@RequestBody Management management){
        int row = managementService.updataById(management);
        return RespBean.success("修改成功！",row);
    }


    //根据管理单位类型查看管理单位列表
    @ApiOperation(value = "根据管理单位类型查看管理单位列表")
    @GetMapping("/managements")
    public RespBean venues(UserListPage userListPage){
        Map<String,Object> map = managementService.page(userListPage);
        return Result.success("获取普通用户列表成功！",map);
    }

}
